<template>
  <!-- 修改资料 -->

  <div>
    <el-form
      :model="form"
      label-position="right"
      ref="formRef"
      :rules="formRules"
    >
      <el-row :gutter="10">
        <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
          <el-form-item label="推荐的会员级别" prop="memberLevelId">
            <el-select
              v-model="form.memberLevelId"
              clearable
              placeholder="请选择："
            >
              <el-option
                v-for="item in configData.memberLevelList"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
          <el-form-item label="被推荐的会员级别" prop="targetMemberLevelId">
            <el-select
              v-model="form.targetMemberLevelId"
              clearable
              placeholder="请选择："
            >
              <el-option
                v-for="item in configData.memberLevelList"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
          <el-form-item label="推荐奖">
            <el-input v-model="form.rewardPoint" type="number" />
          </el-form-item>
        </el-col>
        <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
          <el-form-item label="是否为百分数" prop="isRate">
            <el-switch
              v-model="form.allowRegiste"
              size="large"
              inline-prompt
              :active-icon="Check"
              :inactive-icon="Close"
            />
          </el-form-item>
        </el-col>
        <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
          <el-form-item label="备注" prop="remark">
            <el-input v-model="form.remark" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div class="button-position">
      <el-button @click="updateVisible">取 消</el-button>
      <el-button type="primary" @click="addRecommendPoints(formRef)"
        >确 定</el-button
      >
    </div>
  </div>
</template>
    
  <script setup>
import { reactive, ref, watch, onMounted } from "vue";
import { ElNotification } from "element-plus";
import { Check, Close } from "@element-plus/icons-vue";
import Api from "@/api/model/crm";
import tsMap from "@/components/tsMap/index.vue";
const emit = defineEmits(["updatetable"]);
onMounted(() => {
  getInit();
});

const props = defineProps({
  paramsData: {
    type: Object,
    defalut: {},
  },
});

// 添加用户数据的对象
const form = ref({});
const configData = ref({});
const formRef = ref();
const formRules = reactive({});

const updateVisible = (val) => {
  emit("updatetable");
};

const getInit = async () => {
  let res = await Api.rewardset.add.post();
  console.log(res)
  if (res.code == "200") {
    form.value = res.data;
    configData.value = res.configData
  }
};

const restAddFormData = () => {
  formRef.value.resetFields();
};

// 上传
const addRecommendPoints = async (formRef) => {
  await formRef.validate((valid, fields) => {
    if (valid) {
      addRecommendPointsData();
    }
  });
};

const addRecommendPointsData = async () => {
  // console.log(form.name);
  form.value.transactionKind = '1'
  var params = {
    bean: form.value,
  };
  var res = await Api.rewardset.save.post(params);
  if (res.code == 200) {
    restAddFormData();
    ElNotification.success({
      title: "",
      message: "添加成功！",
      duration: 2000,
    });
    emit("updatetable", true);
  }
};
</script>
    
  <style scoped lang="less">
.borderNone {
  :deep(.el-input__wrapper) {
    box-shadow: 0 0 0 0px var(--el-input-border-color, var(--el-border-color))
      inset;
    cursor: default;
    background-color: transparent;
    border-bottom: 1px solid #999;
    border-radius: 0;

    .el-input__inner {
      cursor: default !important;
    }
  }
}
</style>
    
    